#### Fucking around

library('SDMTools')

grid5k = read.asc.gz('/home1/99/jc152199/MicroclimateStatisticalDownscale/5kASCII/Solar/2006/20061231.asc.gz') #read in the 5kgrid
tt = which(is.finite(grid5k)); grid5k[tt] = c(1:length(tt)) #recode values to be unique number per cell representing an index position

grid250m = read.asc('/home1/99/jc152199/MicroclimateStatisticalDownscale/250mASCII/DEM/ASCII/dem_WTplusbuffer_LatLong_WGS1984_250mres.asc') #read in a 250m grid
pos = as.data.frame(which(is.finite(grid250m), arr.ind=T)) #get the locations
pos$lat = getXYcoords(grid250m)$x[pos$row]
pos$long = getXYcoords(grid250m)$y[pos$col]
pos$grid5k.index = extract.data(cbind(pos$lat,pos$long),grid5k)
for (ii in 1:365) {
#need grass output
#use extract.data on grass output for that day
#calculate mean for each 5k grid
#divide grass values by mean
#append to pos with a column name representing day of year
}

#read in solar rad for day of interest at the 5 k resolution
#tasc = base.asc; tasc[cbind(pos$row,pos$col)] = extract.data(cbind(pos$lat,pos$long),5ksolar.rad) * pos[,"day of year"]
